<?php
$pPageIsPublic = false;
include '../_common.php';

$_SESSION ["m1"] = "restaurant";
$_SESSION ["m2"] = "{$_GET["ss"]}-list";
$objName = "File";
$objUrl = $_GET ["surl"];
$objTitle = "Imagen";

$pTitle = "Nueva {$objTitle}";
$pButton = 'Guardar';
$action = 'add';
$id = intval ( $_REQUEST ['id'] );
$pid = intval ( $_REQUEST ['pid'] );
$seo = NULL;

$tmp = Restaurant::getInstance ();
$tmp->setUid ( $pid );
if (! $tmp->load ())
	Tzn::redirect ( "index.php" );
;

$objLoad = new File ();
$objLoad->setUid ( $id );
if ($objLoad->load ()) {
	$pTitle = "Editar {$objTitle}";
	$pButton = 'Actualizar';
	$action = 'edit';
	$pid = $tmp->id;
	
	if ($_GET ['action'] == 'del') {
		$objLoad->removeFile ();
		$message = "Imagen ha sido eliminado.";
	}
}

if (isset ( $_POST ['submit'] )) {
	$objLoad->setAuto ( $_POST );
	$objLoad->restaurant->id = $_POST ["pid"];
	$objLoad->uploadFile ();
	if ($_POST ['action'] == 'edit') {
		$objLoad->getConnection ();
		$objLoad->setUid ( $id );
		$objLoad->update ();
		Tzn::redirect ( "{$objUrl}-add.php?id={$objLoad ->restaurant ->id}&tab=file", "{$objTitle} ha sido actualizado." );
	} elseif ($_POST ['action'] == 'add') {
		$objLoad->add ();
		Tzn::redirect ( "{$objUrl}-add.php?id={$objLoad ->restaurant ->id}&tab=file", "{$objTitle} ha sido registrado." );
	}
}
?>
<?php include("header.php"); ?>
<script type="text/javascript">
$(document).ready(function(){
	$('#frmMain').validate();	
});
</script>
<?php include("sidebar.php"); ?>
<ul id="subnav">
	<li><a class="back"
		href="<?= $objUrl ?>-add.php?id=<?= $pid?>&tab=file"> Atras </a></li>
	<li class="noborder"><a class="add"
		href="<?= $_SERVER["PHP_SELF"] ?>?pid=<?= $pid?>"> Agregar una <?= $objTitle ?> </a>
	</li>
</ul>
<div id="list">
	<h2> <?php echo $pTitle;?> </h2>
	<form action="" method="post" name="frmMain" id="frmMain"
		enctype="multipart/form-data">
		<fieldset>
			<legend> Informaci&oacute;n General </legend>
			<table cellpadding="0" cellspacing="0" class="table-form">
				<tr>
					<th>T&iacute;tulo:</th>
					<td><?php $objLoad ->qText('titulo', '', 'width:548px', 'class="required"');?></td>
				</tr>
				<tr>
					<th>Imagen:</th>
					<td><?php $objLoad ->pFile('ifile', "{$_SERVER['PHP_SELF']}?pid={$objLoad ->restaurant ->id}&id={$objLoad ->id}&action=del&ss={$_GET["ss"]}&surl={$_GET["surl"]}") ?></td>
				</tr>
				<tr>
					<th>Estado:</th>
					<td><?php $objLoad ->arrayToSelect($objLoad ->_arrStatus, 'estado', $objLoad ->status, false, 'width:100px', '');?></td>
				</tr>
			</table>
		</fieldset>
		<div style="margin-top: 10px">
			<input type="hidden" name="id" value="<?php echo $id; ?>" /> <input
				type="hidden" name="pid" value="<?php echo $pid; ?>" /> <input
				type="hidden" name="action" value="<?php echo $action; ?>" /> <input
				type="submit" name="submit" value="<?php echo $pButton; ?>" />
			&nbsp; <input type="reset" value="Cancelar"
				onClick="window.location.href='<?= $objUrl ?>-add.php?id=<?= $pid?>&tab=file'" />
		</div>
	</form>
</div>
<?php include("footer.php"); ?>